home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / pexecutedemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  2.1 KB  |  63 lines

  1. {
  2. GPC demo program for the PExecute functions.
  3. System-independent execution of processes with pipes (real or
  4. emulated ones) between them.
  5.  
  6. Copyright (C) 1999-2001 Free Software Foundation, Inc.
  7.  
  8. Author: Frank Heckenbach <frank@pascal.gnu.de>
  9.  
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License as
  12. published by the Free Software Foundation, version 2.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; see the file COPYING. If not, write to
  21. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA.
  23.  
  24. As a special exception, if you incorporate even large parts of the
  25. code of this demo program into another program with substantially
  26. different functionality, this does not cause the other program to
  27. be covered by the GNU General Public License. This exception does
  28. not however invalidate any other reasons why it might be covered
  29. by the GNU General Public License.
  30. }
  31.  
  32. program PExecuteDemo;
  33.  
  34. uses GPC;
  35.  
  36. var
  37.   PID, Status : Integer;
  38.   ProgramName, ErrMsg : TString;
  39.   ArgV : array [0 .. 1] of CString = (nil, nil);
  40.  
  41. begin
  42.   Writeln ('Enter the name of the program to execute: ');
  43.   Readln (ProgramName);
  44.   ArgV [0] := ProgramName;
  45.   PID := PExecute (ProgramName, PCStrings (@ArgV), ErrMsg, PExecute_One or PExecute_Search or PExecute_Verbose);
  46.   if PID < 0 then
  47.     begin
  48.       Writeln ('Error in PExecute: ', ErrMsg);
  49.       Halt
  50.     end;
  51.   Writeln ('Spawned process #', PID);
  52.   PID := PWait (PID, Status, 0);
  53.   if PID < 0 then
  54.     Writeln ('Error in PWait')
  55.   else
  56.     begin
  57.       if StatusSignaled (Status) then
  58.         Writeln ('Process #', PID, ' was terminated by signal ', StatusTermSignal (Status));
  59.       if StatusExited (Status) then
  60.         Writeln ('Process #', PID, ' terminated with status ', StatusExitCode (Status))
  61.     end
  62. end.
  63.